package zhongbo.java.air.flightpath.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.flightpath.model.entities.FlightPath;
import zhongbo.java.air.flightpath.service.IFlightPathService;


/**
 * @author WeiJin
 * @version 1.0
 * @date 2025/3/31 13:01
 */
@RestController
@RequestMapping("/flightPath")
@Api(tags = "飞行轨迹相关接口")
public class FlightPathController {

    @Autowired
    private IFlightPathService flightPathService;

    /**
     * 保存禁飞区域信息到数据库
     *
     * @param flightPath 禁飞区域信息
     * @return 返回保存的禁飞区域信息
     */
    @PostMapping("/add")
    @ApiOperation("保存飞行轨迹信息")
    public ResultVo<FlightPath> saveFlightPath(@RequestBody FlightPath flightPath) {
        FlightPath resFlightPath = flightPathService.saveFlightPath(flightPath);
        return ResultVo.ok(resFlightPath);
    }

    /**
     * 根据禁飞区域id删除禁飞区域信息
     *
     * @param id 禁飞区域id
     * @return 被删除的禁飞区域id
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除飞行轨迹信息")
    public ResultVo<String> delFlightPath(String id) {
        String deletedId = flightPathService.delFlightPath(id);
        return ResultVo.ok(deletedId);
    }

    /**
     * 修改禁飞区域信息
     *
     * @param flightPath 前端传递过来的修改信息
     * @return 修改后的信息
     */
    @PutMapping("/modify")
    @ApiOperation("修改飞行轨迹信息")
    public ResultVo<FlightPath> modifyFlightPath(@RequestBody FlightPath flightPath) {
        FlightPath newFlightPath = flightPathService.modifyFlightPath(flightPath);
        return ResultVo.ok(newFlightPath);
    }

    /**
     * 根据禁飞区域id查询禁飞区域信息
     *
     * @param id 禁飞区域id
     * @return 禁飞区域信息
     */
    @GetMapping("/query")
    @ApiOperation("根据飞行轨迹id查询飞行轨迹信息")
    public ResultVo<FlightPath> queryFlightPath(String id) {
        FlightPath flightPath = flightPathService.queryById(id);
        return ResultVo.ok(flightPath);
    }

    /**
     * 分页查询禁飞区域信息
     *
     * @param pageNumber 页码
     * @param pageSize   每页记录数
     * @param sourceType   区域类型
     * @param orderBy    排序字段
     * @param orderType  排序类型，true升序 false降序 默认降序
     * @return 禁飞区域分页信息
     */
    @GetMapping("/page")
    @ApiOperation("分页查询飞行轨迹信息")
    public ResultVo<PageVo<FlightPath>> pageFlightPath(
            @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "sourceType", required = false) String sourceType,
            @RequestParam(value = "orderBy", required = false) String orderBy,
            @RequestParam(value = "orderType", required = false, defaultValue = "false") Boolean orderType) {
        PageVo<FlightPath> flightPathPageVo = flightPathService.pageFlightPath(pageNumber, pageSize,
                sourceType, orderBy, orderType);
        return ResultVo.ok(flightPathPageVo);
    }

}
